#!/bin/bash
set -e
export top_002_fname=002
#>>-----------------------------------------------------------------------------------
#顶层项目目录
export PROJECT_TOPDIR=$PWD
#顶层当前配置文件
export CURCFG_FILE=${PROJECT_TOPDIR}/.curconfig.sh
#-------------------------------------------------------------------------------------

#>>env--------------------------------------------------------------------------------
#设置颜色函数
source ${PROJECT_TOPDIR}/a.OEMKIT/scripts/dugi.000.colorsetup.sh
#导入公共变量
source ${PROJECT_TOPDIR}/a.OEMKIT/scripts/dugi.001.envsetup_common.sh
#导入平台变量
source ${PROJECT_TOPDIR}/a.OEMKIT/scripts/dugi.002.envsetup_platform.sh
#-------------------------------------------------------------------------------------

#检查当前机型配置
if [ ! -f ${CURCFG_FILE} ]; then
	serro "检查当前配置文件... [失败]"
	exit 1
fi
source ${CURCFG_FILE}


#重新确定配置文件名称和路径
update_copy_env
update_boot_env
update_kern_env
update_knfs_env
update_rtfs_env
relocate_imgbin_defname

#--------------------------------------------------------------------------------------
#>>boot--------------------------------------------------------------------------------
bver_boot()
{
	local top_002_func=bver_boot
	sinfo "${top_002_fname}:${top_002_func}:> 构建boot版本文件 .. [开始]"
	export BOOT_BUILD_VER_STR="${BOOT_BUILD_VER_HEAD}${BUILD_VER_MIDFIX}${OEMDEV_CUR_TYPE}$(date +%y%m%d%H%M)"
	pnote "更新boot构建版本号: ${BOOT_BUILD_VER_STR}"

	pnote "新建boot版本头文件: $BOOT_BUILD_VER_HDFILE"
	
	echo -e "#ifndef BOOT_BUILD_VER_H"                                >  ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_BUILD_VER_H"                                >> ${BOOT_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_${OEMDEV_CUR_CPUCODE}_${OEMDEV_CUR_APPAREA}_${OEMDEV_CUR_TYPE} 1" >> ${BOOT_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_BUILD_VER_STR \"${BOOT_BUILD_VER_STR}\""    >> ${BOOT_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDHDSIZ_${OEMDEV_CUR_MTDHDSIZ}  \t1"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDFSTYP_${OEMDEV_CUR_MTDFSTYP}  \t1"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDHDTYP_${OEMDEV_CUR_MTDHDTYP}  \t1"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDFSPAT_${OEMDEV_CUR_MTDFSPAT}  \t1"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDSUB_BOOT    ${OEMDEV_MTDSUB_BOOT}"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDSUB_KNFS    ${OEMDEV_MTDSUB_KNFS}"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDSUB_RTFS    ${OEMDEV_MTDSUB_RTFS}"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDSUB_OVFS    ${OEMDEV_MTDSUB_OVFS}"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDSUB_EXTD    ${OEMDEV_MTDSUB_EXTD}"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDSUB_ROOT    ${OEMDEV_MTDSUB_ROOT}"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDSUB_DATA    ${OEMDEV_MTDSUB_DATA}"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#define BOOT_MTDSUB_VEND    ${OEMDEV_MTDSUB_VEND}"       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${BOOT_BUILD_VER_HDFILE}
	echo -e "#endif"                                                  >> ${BOOT_BUILD_VER_HDFILE}

    echo  "${BOOT_BUILD_VER_STR}" > ${BOOT_BUILD_VER_FLOG}
	sinfo "${top_002_fname}:${top_002_func}:> 构建boot版本文件 .. [完成]"
}
make_boot_bverh()
{
	cd ${SYSKIT_BOOT_RAWDIR_PATH}
	bver_boot
	make_boot
	copy_boot
	cd -> /dev/null
}
dcfg_boot()
{
	local top_002_func=dcfg_boot
	sinfo "${top_002_fname}:${top_002_func}:> 恢复默认配置boot .. [开始]"
	read -p "确认恢复boot默认配置(y/n): " choice
	if [ ! "x${choice}" == "xy" ]; then
		sinfo "默认配置boot：${SYSKIT_BOOT_CFG_NAME} [终止]"
		return 1
	fi
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 001.inner_build_boot.sh ]; then
		. ./001.inner_build_boot.sh subbuild 1
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到001.inner_build_boot.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 恢复默认配置boot .. [完成]"
	cd -> /dev/null
}
mcfg_boot()
{
	local top_002_func=mcfg_boot
	sinfo "${top_002_fname}:${top_002_func}:> 菜单配置boot .. [开始]"
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 001.inner_build_boot.sh ]; then
		. ./001.inner_build_boot.sh subbuild 2
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到001.inner_build_boot.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 菜单配置boot .. [完成]"
	cd -> /dev/null
}
make_boot()
{
	local top_002_func=make_boot
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	sinfo "${top_002_fname}:${top_002_func}:> 编译boot源码: [开始]"
	if [ -f 001.inner_build_boot.sh ]; then
		. ./001.inner_build_boot.sh subbuild 3
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到001.inner_build_boot.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 编译boot源码：[完成]"
	cd -> /dev/null
	return 0
}
clean_boot()
{
	local top_002_func=clean_boot
	sinfo "${top_002_fname}:${top_002_func}:> 清除编译boot内容: [开始]"
	read -p "确认清除编译(y/n): " choice
	if [ ! "x${choice}" == "xy" ]; then
		serro "清除boot编译内容: [终止]"
		return 1
	fi
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 001.inner_build_boot.sh ]; then
		. ./001.inner_build_boot.sh subbuild 4
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到001.inner_build_boot.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 清除编译boot内容：[完成]"
	cd -> /dev/null
	return 0
}
copy_boot()
{
	local top_002_func=copy_boot
	sinfo "${top_002_fname}:${top_002_func}:> 拷贝编译boot内容: [开始]"
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 001.inner_build_boot.sh ]; then
		. ./001.inner_build_boot.sh subbuild 5
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到001.inner_build_boot.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 拷贝编译boot内容：[完成]"
	cd -> /dev/null
	return 0
}
pack_boot()
{
	local top_002_func=pack_boot
	sinfo "${top_002_fname}:${top_002_func}:> 打包压缩boot内容: [开始]"
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 001.inner_build_boot.sh ]; then
		. ./001.inner_build_boot.sh subbuild 6
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到001.inner_build_boot.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 打包压缩boot内容：[完成]"
	cd -> /dev/null
	return 0
}
scfg_boot()
{
	local top_002_func=scfg_boot
	sinfo "${top_002_fname}:${top_002_func}:> 保存当前boot配置: [开始]"
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 001.inner_build_boot.sh ]; then
		. ./001.inner_build_boot.sh subbuild 7
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到001.inner_build_boot.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 保存当前boot配置：[完成]"
	cd -> /dev/null
	return 0
}
#--------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------
#>>kern--------------------------------------------------------------------------------
bver_kern()
{
	local top_002_func=bver_kern
	sinfo "${top_002_fname}:${top_002_func}:> 构建kern版本文件 .. [开始]"
	
	export KERN_BUILD_VER_STR="${KERN_BUILD_VER_HEAD}${BUILD_VER_MIDFIX}${OEMDEV_CUR_TYPE}$(date +%y%m%d%H%M)"
	pnote "更新kern构建版本号: ${KERN_BUILD_VER_STR}"

	pnote "新建kern版本头文件: $KERN_BUILD_VER_HDFILE"

	echo -e "#ifndef KERN_BUILD_VER_H"                                >  ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_BUILD_VER_H"                                >> ${KERN_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_${OEMDEV_CUR_CPUCODE}_${OEMDEV_CUR_APPAREA}_${OEMDEV_CUR_TYPE} 1" >> ${KERN_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_BUILD_VER_STR \"${KERN_BUILD_VER_STR}\""    >> ${KERN_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDHDSIZ_${OEMDEV_CUR_MTDHDSIZ}  \t1"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDFSTYP_${OEMDEV_CUR_MTDFSTYP}  \t1"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDHDTYP_${OEMDEV_CUR_MTDHDTYP}  \t1"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDFSPAT_${OEMDEV_CUR_MTDFSPAT}  \t1"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDSUB_BOOT    ${OEMDEV_MTDSUB_BOOT}"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDSUB_KNFS    ${OEMDEV_MTDSUB_KNFS}"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDSUB_RTFS    ${OEMDEV_MTDSUB_RTFS}"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDSUB_OVFS    ${OEMDEV_MTDSUB_OVFS}"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDSUB_EXTD    ${OEMDEV_MTDSUB_EXTD}"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDSUB_ROOT    ${OEMDEV_MTDSUB_ROOT}"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDSUB_DATA    ${OEMDEV_MTDSUB_DATA}"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#define KERN_MTDSUB_VEND    ${OEMDEV_MTDSUB_VEND}"       >> ${KERN_BUILD_VER_HDFILE}
	echo -e " "                                                       >> ${KERN_BUILD_VER_HDFILE}
	echo -e "#endif"                                                  >> ${KERN_BUILD_VER_HDFILE}
    echo  "${KERN_BUILD_VER_STR}" > ${KERN_BUILD_VER_FLOG}
	sinfo "${top_002_fname}:${top_002_func}:> 构建kern版本文件 .. [完成]"
}
make_kern_bverh()
{
	cd ${SYSKIT_KERN_RAWDIR_PATH}
	bver_kern
	make_kern
	copy_kern
	cd -> /dev/null
}
dcfg_kern()
{
	local top_002_func=dcfg_kern
	sinfo "${top_002_fname}:${top_002_func}:> 恢复默认配置kern .. [开始]"
	read -p "确认恢复kern默认配置(y/n): " choice
	if [ ! "x${choice}" == "xy" ]; then
		sinfo "默认配置kern：${SYSKIT_BOOT_CFG_NAME} [终止]"
		return 1
	fi
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 002.inner_build_kern.sh ]; then
		. ./002.inner_build_kern.sh subbuild 1
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到002.inner_build_kern.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 恢复默认配置kern .. [完成]"
	cd -> /dev/null
}
mcfg_kern()
{
	local top_002_func=mcfg_kern
	sinfo "${top_002_fname}:${top_002_func}:> 菜单配置kern .. [开始]"
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 002.inner_build_kern.sh ]; then
		. ./002.inner_build_kern.sh subbuild 2
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到002.inner_build_kern.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 菜单配置kern .. [完成]"
	cd -> /dev/null
}

make_kern()
{
	local top_002_func=make_kern
	pinfo "${top_002_fname}:${top_002_func}:> SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSTART"
	sinfo "${top_002_fname}:${top_002_func}:> 构建内核: [开始]"
	#--------------------------------------
	cd ${SYSKIT_KERN_RAWDIR_PATH}
	if [ ! -f ${BOOT_BUILD_VER_HDFILE} ]; then

		serro "${top_002_fname}:${top_002_func}:> 检测boot构建版本头文件: ${BOOT_BUILD_VER_HDFILE} [不存在]"
		serro "${top_002_fname}:${top_002_func}:> 请先构建boot源码！"
		return 1
	fi
	cp ${BOOT_BUILD_VER_HDFILE} ${SYSKIT_KERN_RAWDIR_PATH}/include/
	cd -> /dev/null
	sdone "${top_002_fname}:${top_002_func}:> 拷贝boot版本头文件 [完成]"
	#--------------------------------------

	#--------------------------------------
	chown_knfs_root
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	sinfo "${top_002_fname}:${top_002_func}:> 第一次编译kern源码: [开始]"
	if [ -f 002.inner_build_kern.sh ]; then
		. ./002.inner_build_kern.sh subbuild 3 > /dev/null 
		if [ $? -ne 0 ]; then
			serro "${top_002_fname}:${top_002_func}:> 第一次编译kern源码：[失败]"
			return 1
		fi
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到002.inner_build_kern.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	cd -> /dev/null
	sdone "${top_002_fname}:${top_002_func}:> 第一次编译kern源码：[完成]"
	chown_knfs_user
	#--------------------------------------

	#--------------------------------------
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	sinfo "${top_002_fname}:${top_002_func}:> 编译kern驱动模块: [开始]"
	if [ -f 002.inner_build_kern.sh ]; then
		. ./002.inner_build_kern.sh subbuild 8 > /dev/null 
		if [ $? -ne 0 ]; then
			serro "${top_002_fname}:${top_002_func}:> 编译kern驱动模块：[失败]"
			return 1
		fi
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到002.inner_build_kern.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	cd -> /dev/null
	sdone "${top_002_fname}:${top_002_func}:> 编译kern驱动模块：[完成]"
	#--------------------------------------

	#--------------------------------------
	build_knfs_out
	build_knfs_init
	#--------------------------------------
	
	#--------------------------------------
	chown_knfs_root
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	sinfo "${top_002_fname}:${top_002_func}:> 第二次编译kern源码: [开始]"
	if [ -f 002.inner_build_kern.sh ]; then
		. ./002.inner_build_kern.sh subbuild 3 > /dev/null 
		if [ $? -ne 0 ]; then
			serro "${top_002_fname}:${top_002_func}:> 第二次编译kern源码：[失败]"
			return 1
		fi
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到002.inner_build_kern.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	cd -> /dev/null
	sdone "${top_002_fname}:${top_002_func}:> 第二次编译kern源码：[完成]"
	chown_knfs_user
	#--------------------------------------
	
	sdone "${top_002_fname}:${top_002_func}:> 构建内核: [完成]"
	pinfo "${top_002_fname}:${top_002_func}:> EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEND"
	return 0
}

clean_kern()
{
	local top_002_func=clean_kern
	sinfo "${top_002_fname}:${top_002_func}:> 清除编译kern内容: [开始]"
	read -p "确认清除编译(y/n): " choice
	if [ ! "x${choice}" == "xy" ]; then
		serro "清除kern编译内容: [终止]"
		return 1
	fi
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 002.inner_build_kern.sh ]; then
		. ./002.inner_build_kern.sh subbuild 4
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到002.inner_build_kern.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 清除编译kern内容：[完成]"
	cd -> /dev/null
	return 0
}

copy_kern()
{
	local top_002_func=copy_kern
	pinfo "${top_002_fname}:${top_002_func}:> SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSTART"
	sinfo "${top_002_fname}:${top_002_func}:> 拷贝kern内容: [开始]"
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 002.inner_build_kern.sh ]; then
		. ./002.inner_build_kern.sh subbuild 5
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到002.inner_build_kern.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	cd -> /dev/null
	sdone "${top_002_fname}:${top_002_func}:> 拷贝kern内容：[完成]"
	pinfo "${top_002_fname}:${top_002_func}:> EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEND"
	return 0
}
pack_kern()
{
	local top_002_func=pack_kern
	sinfo "${top_002_fname}:${top_002_func}:> 打包压缩kern内容: [开始]"
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 002.inner_build_kern.sh ]; then
		. ./002.inner_build_kern.sh subbuild 6
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到002.inner_build_kern.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 打包压缩kern内容：[完成]"
	cd -> /dev/null
	return 0
}
scfg_kern()
{
	local top_002_func=scfg_kern
	sinfo "${top_002_fname}:${top_002_func}:> 保存当前kern配置: [开始]"
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 002.inner_build_kern.sh ]; then
		. ./002.inner_build_kern.sh subbuild 7
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到002.inner_build_kern.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	sdone "${top_002_fname}:${top_002_func}:> 保存当前kern配置：[完成]"
	cd -> /dev/null
	return 0
}

#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#>>knfs-------------------------------------------------------------------------------
chown_knfs_root()
{
	if [ ! -d ${SYSKIT_KNFS_OUT_PATH} ]; then
		serro "chown_knfs_root: ${SYSKIT_KNFS_OUT_PATH} [不存在]"
		return 1
	fi
	cd ${SYSKIT_KNFS_OUT_PATH}
	sudo chown root:root -R ./*
	cd -> /dev/null
	return 0
}
chown_knfs_user()
{
	if [ ! -d ${SYSKIT_KNFS_OUT_PATH} ]; then
		serro "chown_knfs_root: ${SYSKIT_KNFS_OUT_PATH} [不存在]"
		return 1
	fi
	cd ${SYSKIT_KNFS_OUT_PATH}
	sudo chown $(whoami):$(whoami) -R ./*
	cd -> /dev/null
	return 0
}
build_knfs_init()
{
	local top_002_func=build_knfs_init
	pinfo "${top_002_fname}:${top_002_func}:> SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSTART"
	sinfo "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的/init [开始]"
	if [ ! -f ${KNFKIT_TOPDIR}/998.build.sh ]; then
		return
	fi
	cd  ${KNFKIT_TOPDIR}
	. ./998.build.sh subbuild  1 > /dev/null 2>&1
	. ./998.build.sh subbuild  4 > /dev/null 2>&1
	cd - > /dev/null
	sdone "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的/init [完成]"
	pinfo "${top_002_fname}:${top_002_func}:> EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEND"
}
build_knfs_out()
{
	local top_002_func=build_knfs_out
	pinfo "${top_002_fname}:${top_002_func}:> SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSTART"
	if [ -d ${SYSKIT_KNFS_RAWDIR_PATH}/ual ]; then
		rm -rf ${SYSKIT_KNFS_RAWDIR_PATH}/ual > /dev/null 2>&1
		sdone "${top_002_fname}:${top_002_func}:> 删除z.src.knfs中/ual目录，防止U盘/SD卡在knfs阶段被挂载 [完成]"
	fi

	if [ -d ${SYSKIT_KERN_OUT_PATH}/modules.install ]; then
		sinfo "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的/lib/modules [开始]"
		rm -rf ${SYSKIT_KNFS_RAWDIR_PATH}/lib/modules > /dev/null 2>&1
		cp -rf ${SYSKIT_KERN_OUT_PATH}/modules.install/lib/modules ${SYSKIT_KNFS_RAWDIR_PATH}/lib/modules
		sdone "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的/lib/modules [完成]"
	fi

	if [ ! -d ${SYSKIT_KNFS_RAWDIR_PATH}/dev ]; then
		sinfo "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的/dev [开始]"
		sudo cp -rf ${SYSKIT_KNFS_DEVDIR_PATH} ${SYSKIT_KNFS_RAWDIR_PATH}/dev
		sdone "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的/dev [完成]"
	fi
	if [ -d ${SYSKIT_RTFS_OUT_PATH}/etc ]; then
		rm -rf ${SYSKIT_KNFS_RAWDIR_PATH}/etc > /dev/null 2>&1
		sinfo "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的/etc内容 [开始]"
		cp -rf ${SYSKIT_RTFS_OUT_PATH}/etc ${SYSKIT_KNFS_RAWDIR_PATH}/
		#删除不需要恢复的user.cfg
		rm -rf ${SYSKIT_KNFS_RAWDIR_PATH}/etc/user.cfg
		sdone "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的/etc内容 [完成]"
	fi

	if [ -d ${SYSKIT_RTFS_OUT_PATH}/reset ]; then
		sinfo "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的/reset内容 [开始]"
		rm -rf ${SYSKIT_KNFS_RAWDIR_PATH}/reset > /dev/null 2>&1
		cp -rf ${SYSKIT_RTFS_OUT_PATH}/reset ${SYSKIT_KNFS_RAWDIR_PATH}/
		sdone "${top_002_fname}:${top_002_func}:> 更新z.src.knfs的reset内容 [完成]"
	fi

	sinfo "${top_002_fname}:${top_002_func}:> 拷贝新的z.out.knfs目录：${SYSKIT_KNFS_OUT_PATH} [开始]"
	sudo rm -rf  ${SYSKIT_KNFS_OUT_PATH}
	sudo cp -rfp ${SYSKIT_KNFS_RAWDIR_PATH}      ${SYSKIT_KNFS_OUT_PATH}
	sdone "${top_002_fname}:${top_002_func}:> 拷贝新的z.out.knfs目录：${SYSKIT_KNFS_OUT_PATH} [完成]"
	
	pinfo "${top_002_fname}:${top_002_func}:> EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEND"
}

#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#>>rtfs-------------------------------------------------------------------------------
chown_rtfs_root()
{
	if [ ! -d ${SYSKIT_RTFS_OUT_PATH} ]; then
		serro "chown_rtfs_root: ${SYSKIT_RTFS_OUT_PATH} [不存在]"
		return 1
	fi
	cd ${SYSKIT_RTFS_OUT_PATH}
	sudo chown root:root -R ./*
	cd -> /dev/null
	return 0
}

chown_rtfs_user()
{
	if [ ! -d ${SYSKIT_RTFS_OUT_PATH} ]; then
		serro "chown_rtfs_root: ${SYSKIT_RTFS_OUT_PATH} [不存在]"
		return 1
	fi
	cd ${SYSKIT_RTFS_OUT_PATH}
	sudo chown $(whoami):$(whoami) -R ./*
	cd -> /dev/null
	return 0
}


update_rtfs_bverh()
{
	local top_002_func=update_rtfs_bverh
	pinfo "${top_002_fname}:${top_002_func}:> SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSTART"
	export RTFS_BUILD_VER_STR="${RTFS_BUILD_VER_HEAD}${BUILD_VER_MIDFIX}${OEMDEV_CUR_TYPE}$(date +%y%m%d%H%M)"
	pnote "更新rtfs构建版本号: ${RTFS_BUILD_VER_STR}"

	pnote "新建rtfs版本头文件: $RTFS_BUILD_VER_HDFILE"

	echo -e "#ifndef RTFS_BUILD_VER_H"                               >  ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_BUILD_VER_H"                               >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_U${OEMDEV_CUR_TYPE} 1"                     >> ${RTFS_BUILD_VER_HDFILE}
	echo -e " "                                                      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_BUILD_VER_STR \"${RTFS_BUILD_VER_STR}\""   >> ${RTFS_BUILD_VER_HDFILE}
	echo -e " "                                                      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDHDSIZ_${OEMDEV_CUR_MTDHDSIZ}  \t1"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDFSTYP_${OEMDEV_CUR_MTDFSTYP}  \t1"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDHDTYP_${OEMDEV_CUR_MTDHDTYP}  \t1"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDFSPAT_${OEMDEV_CUR_MTDFSPAT}  \t1"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e " "                                                      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDSUB_BOOT    ${OEMDEV_MTDSUB_BOOT}"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDSUB_KNFS    ${OEMDEV_MTDSUB_KNFS}"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDSUB_RTFS    ${OEMDEV_MTDSUB_RTFS}"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDSUB_OVFS    ${OEMDEV_MTDSUB_OVFS}"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDSUB_EXTD    ${OEMDEV_MTDSUB_EXTD}"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDSUB_ROOT    ${OEMDEV_MTDSUB_ROOT}"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDSUB_DATA    ${OEMDEV_MTDSUB_DATA}"      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#define RTFS_MTDSUB_VEND    ${OEMDEV_MTDSUB_VEND}"      >> ${RTFS_BUILD_VER_HDFILE}

	echo -e " "                                                      >> ${RTFS_BUILD_VER_HDFILE}
	if [ -n "${OEMDEV_MTDIDX_BOOT}" ]; then
		echo -e "#define RTFS_MTDIDX_BOOT    ${OEMDEV_MTDIDX_BOOT}"      >> ${RTFS_BUILD_VER_HDFILE}
	fi
	if [ -n "${OEMDEV_MTDIDX_KNFS}" ]; then
		echo -e "#define RTFS_MTDIDX_KNFS    ${OEMDEV_MTDIDX_KNFS}"      >> ${RTFS_BUILD_VER_HDFILE}
	fi
	if [ -n "${OEMDEV_MTDIDX_RTFS}" ]; then
		echo -e "#define RTFS_MTDIDX_RTFS    ${OEMDEV_MTDIDX_RTFS}"      >> ${RTFS_BUILD_VER_HDFILE}
	fi
	if [ -n "${OEMDEV_MTDIDX_OVFS}" ]; then
		echo -e "#define RTFS_MTDIDX_OVFS    ${OEMDEV_MTDIDX_OVFS}"      >> ${RTFS_BUILD_VER_HDFILE}
	fi
	if [ -n "${OEMDEV_MTDIDX_EXTD}" ]; then
		echo -e "#define RTFS_MTDIDX_EXTD    ${OEMDEV_MTDIDX_EXTD}"      >> ${RTFS_BUILD_VER_HDFILE}
	fi
	if [ -n "${OEMDEV_MTDIDX_ROOT}" ]; then
		echo -e "#define RTFS_MTDIDX_ROOT    ${OEMDEV_MTDIDX_ROOT}"      >> ${RTFS_BUILD_VER_HDFILE}
	fi
	if [ -n "${OEMDEV_MTDIDX_DATA}" ]; then
		echo -e "#define RTFS_MTDIDX_DATA    ${OEMDEV_MTDIDX_DATA}"      >> ${RTFS_BUILD_VER_HDFILE}
	fi
	if [ -n "${OEMDEV_MTDIDX_VEND}" ]; then
		echo -e "#define RTFS_MTDIDX_VEND    ${OEMDEV_MTDIDX_VEND}"      >> ${RTFS_BUILD_VER_HDFILE}
	fi

	if [ "x${OEMDEV_CUR_MTDFSTYP}" == "xUBIFS" ]; then
		echo -e " "                                                      >> ${RTFS_BUILD_VER_HDFILE}
		if [ -n "${OEMDEV_UBIIDX_BOOT}" ]; then
			echo -e "#define RTFS_UBIIDX_BOOT    ${OEMDEV_UBIIDX_BOOT}"      >> ${RTFS_BUILD_VER_HDFILE}
		fi
		if [ -n "${OEMDEV_UBIIDX_KNFS}" ]; then
			echo -e "#define RTFS_UBIIDX_KNFS    ${OEMDEV_UBIIDX_KNFS}"      >> ${RTFS_BUILD_VER_HDFILE}
		fi
		if [ -n "${OEMDEV_UBIIDX_RTFS}" ]; then
			echo -e "#define RTFS_UBIIDX_RTFS    ${OEMDEV_UBIIDX_RTFS}"      >> ${RTFS_BUILD_VER_HDFILE}
		fi
		if [ -n "${OEMDEV_UBIIDX_OVFS}" ]; then
			echo -e "#define RTFS_UBIIDX_OVFS    ${OEMDEV_UBIIDX_OVFS}"      >> ${RTFS_BUILD_VER_HDFILE}
		fi
		if [ -n "${OEMDEV_UBIIDX_EXTD}" ]; then
			echo -e "#define RTFS_UBIIDX_EXTD    ${OEMDEV_UBIIDX_EXTD}"      >> ${RTFS_BUILD_VER_HDFILE}
		fi
		if [ -n "${OEMDEV_UBIIDX_ROOT}" ]; then
			echo -e "#define RTFS_UBIIDX_ROOT    ${OEMDEV_UBIIDX_ROOT}"      >> ${RTFS_BUILD_VER_HDFILE}
		fi
		if [ -n "${OEMDEV_UBIIDX_DATA}" ]; then
			echo -e "#define RTFS_UBIIDX_DATA    ${OEMDEV_UBIIDX_DATA}"      >> ${RTFS_BUILD_VER_HDFILE}
		fi
		if [ -n "${OEMDEV_UBIIDX_VEND}" ]; then
			echo -e "#define RTFS_UBIIDX_VEND    ${OEMDEV_UBIIDX_VEND}"      >> ${RTFS_BUILD_VER_HDFILE}
		fi
	fi

	echo -e " "                                                      >> ${RTFS_BUILD_VER_HDFILE}
	echo -e "#endif"                                                 >> ${RTFS_BUILD_VER_HDFILE}
    echo  "${RTFS_BUILD_VER_STR}" > ${RTFS_BUILD_VER_FLOG}
	pinfo "${top_002_fname}:${top_002_func}:> EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEND"
}

create_rtfsout()
{
	#-----------------------------------------------------------------------
	local top_002_func=create_rtfsout
	pinfo "${top_002_fname}:${top_002_func}:> SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSTART"
	sinfo "${top_002_fname}:${top_002_func}:> 构建z.out.rtfs内容 [开始]"

	#-----------------------------------------------------------------------
	rm -rf  ${SYSKIT_RTFS_OUT_PATH}
	sdone "${top_002_fname}:${top_002_func}:> 删除当前z.out.rtfs目录 [完成]"
	
	#-----------------------------------------------------------------------
	echo "U${OEMDEV_CUR_TYPE}"	> ${SYSKIT_RTFS_RAWDIR_PATH}/etc/rtfshostname
	snote "${top_002_fname}:${top_002_func}:> z.src.rtfs更新主机名称为: U${OEMDEV_CUR_TYPE}"
	
	#-----------------------------------------------------------------------
	if [ -f ${SYSKIT_RTFS_RAWDIR_PATH}/etc/user.cfg/user.wifiapmset.cfg ]; then
		sed  -i "/ssid=/c \ssid=U${OEMDEV_CUR_TYPE}" ${SYSKIT_RTFS_RAWDIR_PATH}/etc/user.cfg/user.wifiapmset.cfg
		snote "${top_002_fname}:${top_002_func}:> z.src.rtfs更新AP节点名称为: U${OEMDEV_CUR_TYPE}"
	fi

	#-----------------------------------------------------------------------
	sinfo "${top_002_fname}:${top_002_func}:> z.src.rtfs路径为: ${SYSKIT_RTFS_RAWDIR_PATH}"
	sinfo "${top_002_fname}:${top_002_func}:> z.out.rtfs路径为: ${SYSKIT_RTFS_OUT_PATH}"
	sudo cp -rfp ${SYSKIT_RTFS_RAWDIR_PATH}   ${SYSKIT_RTFS_OUT_PATH}
	sdone "${top_002_fname}:${top_002_func}:> 拷贝: z.src.rtfs 为 z.out.rtfs [完成]"
	
	#-----------------------------------------------------------------------
	chown_rtfs_user
	sdone "${top_002_fname}:${top_002_func}:> 构建z.out.rtfs内容 [完成]"
	pinfo "${top_002_fname}:${top_002_func}:> EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEND"
}

dopack_rtfsout()
{
	local top_002_func=dopack_rtfsout
	pinfo "${top_002_fname}:${top_002_func}:> SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSTART"
	sinfo "${top_002_fname}:${top_002_func}:> 打包rtfs烧写固件: [开始]"
	cd ${SYSKIT_TOPDIR}/${OEMDEV_CUR_CPUCODE}
	if [ -f 003.inner_build_rtfs.sh ]; then
		. ./003.inner_build_rtfs.sh subbuild 1
	else
		serro "${top_002_fname}:${top_002_func}:> 未找到003.inner_build_rtfs.sh [错误]"
		cd -> /dev/null
		return 1
	fi
	cd -> /dev/null
	sdone "${top_002_fname}:${top_002_func}:> 打包rtfs烧写固件: [完成]"
	pinfo "${top_002_fname}:${top_002_func}:> EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEND"
	return 0
}

#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#>>bdrt-------------------------------------------------------------------------------

#以下为废弃-------------------------------------------------------------------------------------
#buildroot>>===============================================================

dconfig_buildroot()
{
	buildroot/scripts/mkcommon.sh -p ${LICHEE_CHIP} -k ${LICHEE_KERN_VER} -b ${LICHEE_BOARD} -m dcbuildroot
	if [ $? -ne 0 ]; then
		serro "Defconfig buildroot [ERROR]"
	else
		sdone "Defconfig buildroot [OK]"
	fi
}

mconfig_buildroot()
{
	buildroot/scripts/mkcommon.sh -p ${LICHEE_CHIP} -k ${LICHEE_KERN_VER} -b ${LICHEE_BOARD} -m mcbuildroot
	if [ $? -ne 0 ]; then
		serro "Menuconfig buildroot [ERROR]"
	else
		sdone "Menuconfig buildroot [OK]"
	fi
}

build_buildroot()
{
	buildroot/scripts/mkcommon.sh -p ${LICHEE_CHIP} -k ${LICHEE_KERN_VER} -b ${LICHEE_BOARD} -m buildroot
	if [ $? -ne 0 ]; then
		serro "Build buildroot [ERROR]"
	else
		sdone "Build buildroot [OK]"
	fi
}

clean_buildroot()
{
	buildroot/scripts/mkcommon.sh -p ${LICHEE_CHIP} -k ${LICHEE_KERN_VER} -b ${LICHEE_BOARD} -m clbuildroot
	if [ $? -ne 0 ]; then
		serro "Clean buildroot [ERROR]"
	else
		sdone "Clean buildroot [OK]"
	fi
}

mconfig_busybox()
{
	buildroot/scripts/mkcommon.sh -p ${LICHEE_CHIP} -k ${LICHEE_KERN_VER} -b ${LICHEE_BOARD} -m mcbusybox
	if [ $? -ne 0 ]; then
		serro "Menuconfig busybox[ERROR]"
	else
		sdone "Menuconfig busybox[OK]"
		sdone "udate file: buildroot/package/busybox/busybox.config"
	fi
}
	
#buildroot<<===============================================================


update_rtfs_rclocal()
{
	if [ ! -f ${RCSKIT_TOPDIR}/998.build.sh ]; then
		return
	fi
	cd  ${RCSKIT_TOPDIR}
	. ./998.build.sh subbuild  1
	. ./998.build.sh subbuild  4
	cd - > /dev/null
}

update_rtfs_sysmgr()
{
	if [ ! -f ${MGRKIT_TOPDIR}/998.build.sh ]; then
		return
	fi
	cd  ${MGRKIT_TOPDIR}
	. ./998.build.sh subbuild  1
	. ./998.build.sh subbuild  4
	cd - > /dev/null
}

make_rtfs_image()
{
	#从新将z.src.rtfs拷贝为z.out.rtfs
	create_rtfsout

	#将z.out.rtfs打包为烧写文件
	dopack_rtfsout
}

make_rtfs_bverh()
{
	#同时更新到z.src.rtfs和z.out.rtfs
	update_rtfs_bverh
	update_rtfs_rclocal
	update_rtfs_sysmgr
	
	#将z.src.rtfs拷贝为z.out.rtfs
	create_rtfsout
	
	#将z.out.rtfs打包为烧写文件
	dopack_rtfsout
}

make_user_obmota()
{
	sinfo "构建user obmota开始: [开始]"
	if [ ! -d ${OTAKIT_TOPDIR} ]; then
		serro "查找目录OTAKIT_TOPDIR：${OTAKIT_TOPDIR} [不存在]"
		return 1
	fi
	cd ${OTAKIT_TOPDIR}

	#用于存放各个部分的构建版本信息
	if [ ! -d verlog ]; then
		mkdir verlog
	fi

	if [ ! -f ${BOOT_BUILD_VER_FLOG} ]; then
		serro "查找boot日志文件: ${BOOT_BUILD_VER_FLOG} [不存在]"
		return 1
	fi
	cp ${BOOT_BUILD_VER_FLOG} ./verlog/
	
	sdone "更新boot日志文件: ${BOOT_BUILD_VER_FLOG} 到 verlog [完成]"

	if [ ! -f ${KERN_BUILD_VER_FLOG} ]; then
		serro "查找kern构建日志文件: ${KERN_BUILD_VER_FLOG} [不存在]"
		return 1
	fi
	cp ${KERN_BUILD_VER_FLOG} ./verlog/
	sdone "更新kern日志文件: ${KERN_BUILD_VER_FLOG} 到 verlog [完成]"

	if [ ! -f ${RTFS_BUILD_VER_FLOG} ]; then
		serro "查找rtfs构建日志文件: ${RTFS_BUILD_VER_FLOG} [不存在]"
		return 1
	fi
	cp ${RTFS_BUILD_VER_FLOG} ./verlog/
	sdone "更新rtfs日志文件: ${RTFS_BUILD_VER_FLOG} 到 verlog [完成]"

	rm -rf ./obmrtfs
	./01.create_obmrtfs_baseon.sh ../z.src.rtfs

	rm -rf ./obmroot
	./02.create_empty_obmroot.sh

	rm -rf ./obmdata
	./03.create_empty_obmdata.sh

	./04.obmota_autopack.sh

	cd -> /dev/null

	if [ -f  ${OTAKIT_TOPDIR}.tar.gz ]; then
		rm -rf ${OTAKIT_TOPDIR}.tar.gz
	fi
	sinfo "打包: ${OTAKIT_TOPDIR}.tar.gz [开始]"
	tar czf ${OTAKIT_TOPDIR}.tar.gz ${OTAKIT_TOPDIR}
	sdone "打包: ${OTAKIT_TOPDIR}.tar.gz [完成]"
	sdone "构建user obmota开始: [完成]"
	return 0
}
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#>>extra---------------------------------------------------------------------------
copy_extra()
{
	local top_002_func=copy_extra
	sinfo "${top_002_fname}:${top_002_func}:> 拷贝extra内容: [开始]"
	
	if [ ! -d ${IMGBINS_SUBDIR} ]; then
		mkdir -p ${IMGBINS_SUBDIR}
	fi
	
	if [ -d ${OEMKIT_DEVICES_DIR}/${OEMDEV_CUR_TYPE}/extra ]; then
		echo "cp -rf ${OEMKIT_DEVICES_DIR}/${OEMDEV_CUR_TYPE}/extra/* ${IMGBINS_SUBDIR}"
		cp -rf ${OEMKIT_DEVICES_DIR}/${OEMDEV_CUR_TYPE}/extra/* ${IMGBINS_SUBDIR}
	fi
	sinfo "${top_002_fname}:${top_002_func}:> 拷贝extra内容: [完成]"
	return 0
}
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------
#>>knfs-------------------------------------------------------------------------------

show_usage()
{ 
	sinfo "--------------------------------------------------"
	sinfo "使用说明:"
	sinfo "--------------------------------------------------"
	snote "$0 01   [生成全部固件:(${SYSKIT_BOOT_BIN_NAME}),(${SYSKIT_KNFS_BIN_NAME}),(${SYSKIT_RTFS_BIN_NAME}) ]"
	sinfo "--------------------------------------------------"
	sinfo "$0 10  [boot编译并更新BF版本号生成: ${SYSKIT_BOOT_BIN_NAME}]"
	sinfo "$0 11  [boot默认配置]"
	sinfo "$0 12  [boot图形配置]"
	sinfo "$0 13  [boot编译源码]"
	sinfo "$0 14  [boot清除编译]"
	sinfo "$0 15  [boot输出拷贝]"
	sinfo "$0 16  [boot源码打包]"
	sinfo "$0 17  [boot保存配置]"
	sinfo "--------------------------------------------------"
	sinfo "$0 20  [kern编译并更新KF版本号生成: ${SYSKIT_KNFS_BIN_NAME}]"
	sinfo "$0 21  [kern默认配置]"
	sinfo "$0 22  [kern图形配置]"
	sinfo "$0 23  [kern编译源码]"
	sinfo "$0 24  [kern清除编译]"
	sinfo "$0 25  [kern输出拷贝]"
	sinfo "$0 26  [kern打包源码]"
	sinfo "$0 27  [kern保存配置]"
	sinfo "--------------------------------------------------"
	sinfo "$0 31  [buildroot复原]"
	sinfo "$0 32  [buildroot配置]"
	sinfo "$0 33  [buildroot编译]"
	sinfo "$0 33  [buildroot清除]"
	sinfo "--------------------------------------------------"
	sinfo "$0 40  [rtfs打包并更新FF版本号生成: ${SYSKIT_RTFS_BIN_NAME}]"
	sinfo "$0 41  [rtfs新建z.out.rtfs]"
	sinfo "$0 42  [rtfs打包z.out.rtfs]"
	sinfo "--------------------------------------------------"
	sinfo "$0 51  [obmota导出范例]"
	sinfo "--------------------------------------------------"
}

main_proc()
{	
	if [ -z "$1" ]; then
		show_usage
		return 1
	else
		#配置编译环境
		check_env

		#检查boot输出目录
		if [ ! -d ${SYSKIT_BOOT_OUT_PATH} ]; then
			mkdir -p ${SYSKIT_BOOT_OUT_PATH}
		fi

		#检查kern输出目录
		if [ ! -d ${SYSKIT_KERN_OUT_PATH} ]; then
			mkdir -p ${SYSKIT_KERN_OUT_PATH}
		fi

		#检查brts输出目录
		if [ ! -d ${SYSKIT_BRTS_OUT_PATH} ]; then
			mkdir -p ${SYSKIT_BRTS_OUT_PATH}
		fi

		#检查knfs输出目录
		if [ ! -d ${SYSKIT_KNFS_OUT_PATH} ]; then
			mkdir -p ${SYSKIT_KNFS_OUT_PATH}
		fi

		#检查rtfs输出目录
		if [ ! -d ${SYSKIT_RTFS_OUT_PATH} ]; then
			mkdir -p ${SYSKIT_RTFS_OUT_PATH}
		fi

		if [ "x$1" = "x01" ]; then
			make_boot_bverh
			make_rtfs_bverh
			make_kern_bverh
			#make_user_obmota
			#拷贝其他工具
			copy_extra
		elif [ "x$1" = "x10" ]; then
			make_boot_bverh
		elif [ "x$1" = "x11" ]; then
			dcfg_boot
		elif [ "x$1" = "x12" ]; then
			mcfg_boot
		elif [ "x$1" = "x13" ]; then
			make_boot
		elif [ "x$1" = "x14" ]; then
			clean_boot
		elif [ "x$1" = "x15" ]; then
			copy_boot
		elif [ "x$1" = "x16" ]; then
			pack_boot
		elif [ "x$1" = "x17" ]; then
			scfg_boot
		elif [ "x$1" = "x20" ]; then
			make_kern_bverh
		elif [ "x$1" = "x21" ]; then
			dcfg_kern
		elif [ "x$1" = "x22" ]; then
			mcfg_kern
		elif [ "x$1" = "x23" ]; then
			make_kern
		elif [ "x$1" = "x24" ]; then
			clean_kern
		elif [ "x$1" = "x25" ]; then
			copy_kern
		elif [ "x$1" = "x26" ]; then
			pack_kern
		elif [ "x$1" = "x27" ]; then
			scfg_kern
		elif [ "x$1" = "x40" ]; then
			make_rtfs_bverh
		elif [ "x$1" = "x41" ]; then
			create_rtfsout
		elif [ "x$1" = "x42" ]; then
			dopack_rtfsout
		elif [ "x$1" = "x51" ]; then
			make_user_obmota
		else
			show_usage
			return
		fi
	fi
}
main_proc  $@
